﻿<UserControl x:Class="FacebookClient.BuddyListControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:FacebookClient="clr-namespace:FacebookClient"
    xmlns:ClientManager="clr-namespace:ClientManager" 
    xmlns:ClientManagerControls="clr-namespace:ClientManager.Controls"
    xmlns:Facebook="clr-namespace:Contigo;assembly=Contigo"
    MinWidth="250"
    x:Name="ThisControl">
  <UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
  </UserControl.Resources>
  <Border Background="{DynamicResource ApplicationBarBackground}" Padding="1" BorderThickness="1" BorderBrush="LightGray"
          Visibility="{Binding ElementName=ThisControl, Path=IsDisplayed, Converter={StaticResource BooleanToVisibilityConverter}}">
    <DockPanel>
      <DockPanel DockPanel.Dock="Top">
        <Button DockPanel.Dock="Right" Margin="5" Content="0" Style="{DynamicResource SimpleButtonStyle}" FontFamily="Webdings" Foreground="White" Command="{x:Static FacebookClient:BuddyListControl.CloseCommand}" ToolTip="Hide buddy list" />
        <TextBlock Text="Who's Online" Foreground="White" FontFamily="{DynamicResource SansSerifFont}" FontSize="{DynamicResource LargeFontSize1}" FontWeight="Bold" Margin="5" />
      </DockPanel>
      <Button x:Name="StartChatButton" 
          DockPanel.Dock="Bottom" 
          Margin="3,5" 
          Height="22" 
          HorizontalAlignment="Right" 
          VerticalAlignment="Top" 
          Click="StartChatButton_Click"
          Style="{DynamicResource StandardButtonStyle}">
        Chat
      </Button>

      <ScrollViewer
          Background="{DynamicResource PopupListControlBackgroundBrush}" 
          VerticalScrollBarVisibility="Auto" 
          HorizontalScrollBarVisibility="Hidden">
        <ListBox x:Name="FriendList" 
            ScrollViewer.VerticalScrollBarVisibility="Disabled" 
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            MinHeight="40" 
            Padding="5" 
            Background="{DynamicResource PopupListControlBackgroundBrush}"
            ItemsSource="{Binding Source={x:Static ClientManager:ServiceProvider.ViewManager}, Path=OnlineFriends}"
            BorderThickness="0">
          <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
              <Setter Property="FocusVisualStyle" Value="{x:Null}" />
              <Setter Property="Background" Value="{DynamicResource PopupListControlBackgroundBrush}" />
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="ListBoxItem">
                    <ContentPresenter />
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </ListBox.ItemContainerStyle>

          <ItemsControl.ItemTemplate>
            <DataTemplate DataType="{x:Type Facebook:FacebookContact}">
              <DockPanel Margin="0,2">
                <Rectangle DockPanel.Dock="Top"
                            Height="1" 
                            SnapsToDevicePixels="True"
                            Width="240" 
                            VerticalAlignment="Top" 
                            HorizontalAlignment="Center" 
                            Fill="{DynamicResource NewsFeedItemDividerBrush}" />
                <Grid>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
                  
                  <FacebookClient:FriendButton
                    Margin="2"
                    Friend="{Binding}" 
                    Click="_OnFriendClicked" 
                    Style="{DynamicResource TinyFriendButtonStyle}"
                    VerticalAlignment="Center"/>
                  <FacebookClient:ContactNameDisplayControl Margin="6,0,0,0" Grid.Column="1" FacebookContact="{Binding}" Foreground="{DynamicResource HyperlinkForegroundBrush}" VerticalAlignment="Center"/>
                </Grid>
              </DockPanel>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ListBox>
      </ScrollViewer>
    </DockPanel>
  </Border>
</UserControl>
